<?php
/*
 * 手机客户端专场-刷新价格接口
 * 2014-06-03
 */
include "../inc/public_header.php";
include "../func/user.php";				//用户信息处理函数
include "../func/bid.php";				//拍卖信息处理函数

//常量
$aid 		= $_REQUEST["aid"];		
$uuid 		= $_REQUEST["uuid"];

//拍品价格
$rs=array("success"=>"0");
$sql = "select if(lastprice = 0,startprice,lastprice) as showprice,bids from auction where aid = '".$aid."'";
$db->query($sql);
if($db->next_record()){
	$getshowprice_showprice = $db->f("showprice");
	$getshowprice_bids = $db->f("bids");
}
$isProxy = "0";
$isLead = "0";
$credit = 0;
$proxyPrice = 0;
if ($getshowprice_bids == 0){
	$isOrigin = "1";
}
else {
	$isOrigin = "0";
}
if (isset($uuid) and strlen($uuid) >= 32){
	//根据UUID查找ID
	$uInfoArr = user_getInfoFromUUID();
	if(!$uInfoArr){
		//"msg"=>"用户ID错误"
		$rs=array("success"=>"0","errCode"=>"0");
	}else{
		$uid = $uInfoArr["uid"];//用户信息主键
		$sql = "SELECT bidproxy,uid from auction_userbidproxy where aid = '".$aid."' AND uid = '".$uid."'";
		$db->query($sql);
		if($db->next_record()){
			$uidaidproxy_bidproxy = $db->f("bidproxy");
			$uidaidproxy_uid = $db->f("uid");
		}
		$userCreditLimit=userCreditLimit($uid);
		//是否领先
		$sql = "select uid,is_bid from auction_userlastbid where aid = '".$aid."' AND uid = '".$uid."'";
		$db->query($sql);
		if($db->next_record()){
			$uidisLead_is_bid = $db->f("is_bid");
			$uidisLead_uid = $db->f("uid");
		}
		if ($uidisLead_uid){
			$isLead = $uidisLead_is_bid;
		}
		if ($uidaidproxy_uid){
			$isProxy = "1";
			$proxyPrice = $uidaidproxy_bidproxy;
		}
		$credit = $userCreditLimit;
	}
}
if($isLead == "1"){
	//在客户端中，可用额度减去了当前价，或者代理价（不该减去），在此加回来，避免客户端显示错误
	if($isProxy == "1"){
		$credit = $credit+$proxyPrice;
	}else{
		$credit = $credit+$getshowprice_showprice;
	}
}
if ($getshowprice_showprice){
	$rs=array("success"=>"1","price"=> $getshowprice_showprice,"proxyPrice"=>$proxyPrice,"isProxy"=>$isProxy,"isLead"=>$isLead,"credit"=>$credit,"isOrigin"=>$isOrigin);
}
echo json_encode($rs);

?>
